home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.10 Oct 94 / QT MIDI Music / MusicTest.p < prev    next >
Encoding:
Text File  |  1994-07-24  |  1.7 KB  |  69 lines  |  [TEXT/PJMM]

  1. PROGRAM MusicTest;
  2.     USES
  3.         Components, Music;
  4.  
  5.     VAR
  6.         h: MusicDescriptionHandle;
  7.         tp: TunePlayer;
  8.         result: ComponentResult;
  9.         theTuneStatus: TuneStatus;
  10.         err: OSErr;
  11.  
  12.     LABEL
  13.         10; { used for error cleanup }
  14. BEGIN
  15.     { Get the music resource and lock it down }
  16.     h := MusicDescriptionHandle(GetResource('Musi', 128));
  17.     IF h = NIL THEN
  18.         ExitToShell;
  19.     HLock(Handle(h));
  20.  
  21.     { open the default tune player }
  22.     tp := OpenDefaultComponent(kTunePlayerType, ResType(LongInt(kAnyComponentType)));
  23.     IF tp = NIL THEN
  24.         ExitToShell;
  25.  
  26.     { tell that we have 600 units per second }
  27.     result := TuneSetTimeScale(tp, 600);
  28.     IF result <> noErr THEN
  29.         GOTO 10;
  30.  
  31.     { Set the header, to tell what instruments are used }
  32.     result := TuneSetHeader(tp, @h^^.headerData);
  33.     IF result <> noErr THEN
  34.         GOTO 10;
  35.  
  36.     { Have it allocate whatever resources are needed }
  37.     result := TunePreRoll(tp);
  38.     IF result <> noErr THEN
  39.         GOTO 10;
  40.  
  41.     { We want to play at normal volume }
  42.     result := TuneSetVolume(tp, $10000);
  43.     IF result <> noErr THEN
  44.         GOTO 10;
  45.  
  46.     { Queue up the music, normal tempo, play everything now }
  47.     result := TuneQueue(tp, Pointer(ORD4(h^) + h^^.size), $10000, 0, $7FFFFFFF, kTuneStartNow, NIL, 0);
  48.     IF result <> noErr THEN
  49.         GOTO 10;
  50.  
  51.     REPEAT
  52.         result := TuneGetStatus(tp, theTuneStatus);
  53.         IF result <> noErr THEN
  54.             GOTO 10;
  55.     { spin until we click the button or no music left queued up }
  56.     UNTIL Button | (theTuneStatus.queueCount = 0);
  57.  
  58.     { We get here either by getting an error or having everything finish }
  59.     { Regardless, we need to stop and clean up everything }
  60. 10:
  61.     IF result <> noErr THEN
  62.         DebugStr('Music result');
  63.     IF tp <> NIL THEN
  64.         result := TuneStop(tp, kStopFadeout);
  65.     IF tp <> NIL THEN
  66.         err := CloseComponent(tp);
  67.  
  68.     { And we are done }
  69. END.